<!DOCTYPE html>
<html>
{include file="public/head"}
<body>
<div class="">
  <form action="{:url('admin/Problem/search')}" method="post" class="layui-form" >
    <div style="text-align: center;">
      <div class="layui-input-inline">
        <div class="layui-form-item">
          <input type="text" name="keyword" placeholder="按题目ID或标题搜索" class="layui-input" value="{$keyword}"/>
        </div>
      </div>
      <div class="layui-input-inline">
        <div class="layui-form-item">
          <input value="开始搜索" type="submit" class="layui-btn" />
        </div>
      </div>
    </div>
  </form>
  <div style="text-align: center;">
    {$page}
  </div>
  <div class="fly-panel" style="margin: 20px 40px 20px 40px;">
    <table class="layui-table">
      <colgroup>
        <col width="150">
        <col width="200">
      </colgroup>
      <thead>
        <tr>
          <th>ID</th>
          <th>Title</th>
          <th>Date</th>
          <th>Status</th>
          <th>Edit</th>
        </tr> 
      </thead>
      <tbody>      
        {foreach name="list" item="v"}
        <tr>
          <td>
            {$v['problem_id']}
          </td>
          <td>
            <a href="{:url('web/Problem/problem',['pid'=>$v['problem_id']])}">{$v['title']}</a>
          </td>
          <td>
            {$v['in_date']}
          </td>
          <td>
              <a class="layui-btn nyoj-status {$v['defunct']=='N'?'':'layui-btn-danger'}" pid="{$v['problem_id']}">{$v['defunct']=='N'?'显示':'隐藏'}</a>
          </td>
          <td>
            <a href="{:url('admin/problem/editor_opt',['flag'=>1,'id'=>$v['problem_id']])}"><button class="layui-btn">编辑</button></a> 
            <a href="{:url('admin/problem/test_data','pid='.$v['problem_id'])}"><button class="layui-btn">测试数据</button></a> 
            <button onclick="del({$v['problem_id']})" class="layui-btn">删除</button>
          </td>
        </tr>
        {/foreach}
      </tbody>
    </table>
  </div>
  <div style="text-align: center;">
    {$page}
  </div>
</div>
{include file="public/end"}
<script type="text/javascript">
  function del(id) {
    if(confirm('确定删除吗?')) {
      window.location.href="{:url('admin/problem/del')}"+'?id='+id;
   }
  }
  
  layui.use(['jquery','layer'],function(){
      var $=layui.jquery;
      var layer=layui.layer;
      $('.nyoj-status').click(function(){
         var pid=$(this).attr('pid');
         var clickthis=this;
         $.get('/admin/api/setstatus/'+pid,function(res){
             layer.msg(res.msg);
             if(res.code===0){
                 if(res.status==='N')
                 {
                     $(clickthis).removeClass(' layui-btn-danger');
                     $(clickthis).text('显示');
                 }
                  else {
                      $(clickthis).addClass(' layui-btn-danger');
                      $(clickthis).text('隐藏');
                }
                
             }
         })
      });
  });
</script>
</html>